<!DOCTYPE HTML>
<html>
<head>
<title>ComObjCreate() | AutoHotkey</title>
<meta name="description" content="The ComObjCreate function creates a COM object." />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>ComObjCreate() <span class="ver">[AHK_L 53+]</span></h1>
<p>创建 COM 对象.</p>
<pre class="Syntax">ComObject := <span class="func">ComObjCreate</span>(CLSID <span class="optional">, IID</span>)</pre>

<h2>参数</h2>
<dl>

  <dt>CLSID</dt>
  <dd><p>要创建的 COM 对象的 CLSID 或可读 Prog ID.</p></dd>

  <dt>IID</dt>
  <dd><p><span class="ver">[v1.0.96.00+]:</span> 对象支持的接口标识符.</p></dd>

</dl>

<h2>返回值</h2>
<p>失败时, 函数可能会抛出异常, 退出脚本或返回空字符串, 具体取决于当前的 <a href="ComObjError.htm">ComObjError()</a> 设置和<a href="ComObjError.htm#factors">其他因素</a>.</p>
<p>如果指定了 IID, 则返回接口指针. 不再使用指针时通常脚本必须调用 <a href="ObjAddRef.htm">ObjRelease()</a>.</p>
<p>否则, 返回脚本可以使用的包装器对象. 请参阅<a href="../Objects.htm#Usage_Objects">对象语法</a>.</p>

<h2>相关</h2>
<a href="ComObjGet.htm">ComObjGet()</a>, <a href="ComObjActive.htm">ComObjActive()</a>, <a href="ComObjConnect.htm">ComObjConnect()</a>, <a href="ComObjArray.htm">ComObjArray()</a>, <a href="ComObjError.htm">ComObjError()</a>, <a href="ComObjQuery.htm">ComObjQuery()</a>, <a href="http://msdn.microsoft.com/en-us/library/dcw63t7z.aspx">CreateObject (MSDN)</a>

<h2>示例</h2>
<p>参阅后面的论坛主题可以看到不断增长的示例列表: <a href="https://www.autohotkey.com/forum/topic61509.html">https://www.autohotkey.com/forum/topic61509.html</a>.</p>
<div class="ex" id="ExIE">
<p><a href="#ExIE">#1</a></p>
<pre>ie := <b>ComObjCreate</b>("InternetExplorer.Application")
ie.Visible := true  <em>; 已知此语句在 IE7 上无法正常执行.</em>
ie.Navigate("https://www.autohotkey.com/")
</pre>
</div>

</body>
</html>